package coder.nav.model.vo;

import coder.nav.enums.NavCashFlagEnums;
import lombok.Data;

import java.math.BigDecimal;
import java.util.*;

/**
 * 线型图
 * @author Bosen 2024/10/16 16:30
 */
@Data
public class NavChartLineVO {

    private List<String> legend;

    private List<String> xaxis;

    private List<Map<String, Object>> data;

    public NavChartLineVO(Set<String> legend, Map<String, Map<String, BigDecimal>> data) {
        this.legend = new ArrayList<>(legend);
        this.xaxis = new ArrayList<>(data.keySet());
        this.data = new ArrayList<>();

        List<String> addList = new ArrayList<>();
        List<String> subList = new ArrayList<>();
        data.forEach((key, value) -> {
            BigDecimal add = value.getOrDefault(NavCashFlagEnums.ADD.getValue(), BigDecimal.ZERO);
            addList.add(add.compareTo(BigDecimal.ZERO) > 0 ? add.toString() : null);
            BigDecimal sub = value.getOrDefault(NavCashFlagEnums.SUB.getValue(), BigDecimal.ZERO);
            subList.add(sub.compareTo(BigDecimal.ZERO) > 0 ? sub.toString() : null);
        });

        Map<String, Object> addMap = new TreeMap<>();
        addMap.put("name", NavCashFlagEnums.ADD.getValue());
        addMap.put("type", "line");
        addMap.put("connectNulls", true);
        addMap.put("data", addList);
        this.data.add(addMap);

        Map<String, Object> subMap = new TreeMap<>();
        subMap.put("name", NavCashFlagEnums.SUB.getValue());
        subMap.put("type", "line");
        subMap.put("connectNulls", true);
        subMap.put("data", subList);
        this.data.add(subMap);

    }

}
